package com.github.baichuan.iot.gateway.telecontrol;


import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;

/**
 * 命令应答通知
 */
@Getter
@ToString
public class CommandEcho {
    @NotBlank(message = "设备编码编码不能为空")
    private String device;

    @NotBlank(message = "命令追踪Id不能为空")
    private String traceId;

    @NotNull(message = "命令状态不能为空")
    private Status status;

    @NotBlank(message = "消息不能为空")
    private String message;

    public CommandEcho(){}

    private CommandEcho(String device, String traceId, String message, Status status){
        this.device = device;
        this.traceId = traceId;
        this.message = message;
        this.status = status;
    }

    public static CommandEcho success(@NonNull Command command, @NonNull  String message){
        return new CommandEcho(command.getDevice(), command.getTraceId(), message, Status.SUCCESS);
    }

    public static CommandEcho success(@NonNull String tbox, @NonNull String traceId, @NonNull String message){
        return new CommandEcho(tbox, traceId, message, Status.SUCCESS);
    }

    public static CommandEcho fail(@NonNull Command command, @NonNull  String message){
        return new CommandEcho(command.getDevice(), command.getTraceId(), message, Status.FAIL);
    }

    public static CommandEcho fail(@NonNull String tbox, @NonNull String traceId, @NonNull String message){
        return new CommandEcho(tbox, traceId, message, Status.FAIL);
    }

    public static CommandEcho pending(@NonNull String tbox, @NonNull String traceId, @NonNull  String message){
        return new CommandEcho(tbox, traceId, message, Status.PENDING);
    }

    public static CommandEcho pending(@NonNull Command command, @NonNull  String message){
        return new CommandEcho(command.getDevice(), command.getTraceId(), message, Status.PENDING);
    }
}
